<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Models\Store;
use App\Models\Coupon;

class UserCoupon extends Model
{
    //用户优惠券
    protected $table = 'user_coupon';

    //關聯門店
    public function store(){
        return $this->belongsTo(Store::class,'store_id','id');
    }

    //關聯優惠券
    public function coupon(){
        return $this->belongsTo(Coupon::class,'coupon_id','id');
    }

    //以整数金额计算 coupon_value
    public function getCouponValueAttribute($key)
    {
        return round($key);
    }

    //查询class_base_info_id
    public function class_base_info()
    {
        return $this->hasOne(ClassBaseInfo::class,'id','class_base_info_id');
    }

}
